<?php echo $this->render('/public/header');?>
<div id="main" class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
    <button onclick="Page.add()" class="btn btn-success">添加产品</button>
    <br/>
    <br/>
    <table class="table table-borderd">
        <thead>
            <tr>
                <th>日期</th>
                <th>invoice</th>
                <th>产品ID</th>
                <th>产品名称</th>
                <th>客户单价($)</th>
                <th>extra fee</th>
                <th>购买数量</th>
                <th>采购单价(￥)</th>
                <th>额外费用(￥)</th>
                <th>额外费用备注</th>
                <th>利润(￥)</th>
                <th>利润比</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($this->params['list'] as $k=>$v):?>
                <tr>
                    <td><?php echo $v['date'];?></td>
                    <td><?php echo $v['invoice'];?></td>
                    <td><?php echo $v['id'];?></td>
                    <td><input onchange="Page.update_product(<?php echo $v['id'];?>,'product_name',this.value)" style="width:100%" type="text" value="<?php echo $v['product_name'];?>" /></td>
                    <td><input onchange="Page.update_product(<?php echo $v['id'];?>,'price_dollar',this.value)" style="width:100%" type="text" value="<?php echo $v['price_dollar'];?>" /></td>
                    <td><input onchange="Page.update_product(<?php echo $v['id'];?>,'customer_extra_fee',this.value)" style="width:100%" type="text" value="<?php echo $v['customer_extra_fee'];?>" /></td>
                    <td><input onchange="Page.update_product(<?php echo $v['id'];?>,'number',this.value)" style="width:100%" type="text" value="<?php echo $v['number'];?>" /> </td>
                    <td><input onchange="Page.update_product(<?php echo $v['id'];?>,'price_rmb',this.value)" style="width:100%" type="text" value="<?php echo $v['price_rmb'];?>"  /> </td>
                    <td><input onchange="Page.update_product(<?php echo $v['id'];?>,'extra_fee',this.value)" style="width:100%" type="text" value="<?php echo $v['extra_fee'];?>" /></td>
                    <td><input onchange="Page.update_product(<?php echo $v['id'];?>,'remark',this.value)" style="width:100%" type="text" value="<?php echo $v['remark'];?>" /></td>
                    <td><?php echo $v['number'];?></td>
                    <td><?php echo $v['number'];?></td>
                </tr>
             <?php endforeach;?>
        </tbody>
    </table>
</div>
<script>
    var Page = {};
    Page.update_product=function(id,column,value){
        layer.confirm("确认修改",{},function(){
            var data = {};
            data.id = id;
            data.column = column;
            data.value = value;
            $.post("/purchase/purchase_update",data,function(res){
                if(res.code==1) {
                    layer.confirm(res.msg,{},function(){
                        window.location.reload();
                    })
                } else {
                    layer.alert(res.msg);
                }
            },'json')
        })
    }

    Page.add=function(){
        zeroModal.show({url:'/api/add_product',title:"添加产品"});
    }

</script>
<?php echo $this->render('/public/footer');?>
